<?php

class template
{
    var $title,$content = "",$page,$sideContent ="",$msg, $user,$menu,$login,$contact;
    function __construct($title,$type = "") {
        $this->title = $title;
        $this->loadData();
    }
    function addMenuItem($name,$link,$color = "blue")
    {
        if($color == "blue")
        {
            $this->sideContent .= '<a href="'.$link.'" class="menuitem" href="">'.$name.'</a>';
        }else if($color == "green")
        {
            $this->sideContent .= '<a href="'.$link.'" class="menuitem_green" href="">'.$name.'</a>';
        }else if($color == "red")
        {
            $this->sideContent .= '<a href="'.$link.'" class="menuitem_red" href="">'.$name.'</a>';
        }else
        {
            $this->sideContent .= '<a href="'.$link.'" class="menuitem" href="">'.$name.'</a>';
        }
        
    }
    function showContact($contact)
    {
        $this->contact = $contact;
    }
    function showUser($users)
    {
        $this->user = $users;
    }
    function showMsg($msgs)
    {
        $this->msg = $msgs;
    }
    function showMenu($msgs)
    {
        $this->menu = $msgs;
    }
    function showLogin($msgs)
    {
        $this->login = $msgs;
    }
    function setTitle($title)
    {
        $this->title;
    }
    function addContent($data) {
        $this->content .= $data;
    }
    function addHeader($data)
    {
        $this->content .= "<h1>".$data."</h1>";
    }
    function addParagraph($data)
    {
        $this->content .= '<p>'.$data.'</p>';
    }
    private function loadData()
    {
        $this->page = file_get_contents("./template/template.php");
    }
    private function compileAndReplace()
    {
        $this->replacePage($this->content, "#!content!#");
        $this->replacePage($this->title, "#!title!#");
        $this->replacePage($this->sideContent, "#!sideContent!#");
        $this->replacePage($this->user, "#!logged!#");
        $this->replacePage($this->msg, "#!msg!#");
        $this->replacePage($this->menu, "#!menu!#");
        $this->replacePage($this->login, "#!login!#");
        $this->replacePage($this->contact, "#!contact!#");
    }
    private function replacePage($data,$replaceName)
    {
        $this->page = str_replace($replaceName, $data, $this->page);
    }
    function genPage()
    {
        $this->compileAndReplace();
        echo $this->page;
    }
}
?>
